package android.tong;

import android.tong.R;
import android.util.Log;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class Hello extends Activity {
    /** Called when the activity is first created. */
	private static final String TAG = "HELLO";
	public static final int ADD_ID = Menu.FIRST;
	public static final int DEL_ID = Menu.FIRST + 1;
	public static final int EXIT_ID = Menu.FIRST + 2;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.v(TAG, "Hello->onCreate");
        setContentView(R.layout.main);
        Button btn_OK = (Button)findViewById(R.id.btnOK);
        btn_OK.setOnClickListener(myClick);
        Button btn_Show = (Button)findViewById(R.id.btnShow);
        btn_Show.setOnClickListener(myClick);
        Button btn_MenuList = (Button)findViewById(R.id.btnMenuList);
        btn_MenuList.setOnClickListener(myClick);
        Button btn_MenuList2 = (Button)findViewById(R.id.btnMenuList2);
        btn_MenuList2.setOnClickListener(myClick);
        
        Button btn_Browser = (Button)findViewById(R.id.btnBrowser);
        btn_Browser.setOnClickListener(myClick);
        Button btn_Exit = (Button)findViewById(R.id.btnExit);
        btn_Exit.setOnClickListener(myClick);
        Button btn_Title = (Button)findViewById(R.id.btnTitle);
        btn_Title.setOnClickListener(myClick);
        Button btn_PlayMusic = (Button)findViewById(R.id.btnPlayMusic);
        btn_PlayMusic.setOnClickListener(myClick);
        
        Button btn_Layout = (Button) findViewById(R.id.btnLayout);
        btn_Layout.setOnClickListener(myClick);
        
        Button btn_RLayout = (Button) findViewById(R.id.btnRLayout);
        btn_RLayout.setOnClickListener(myClick);
        
        Button btn_TLayout = (Button) findViewById(R.id.btnTLayout);
        btn_TLayout.setOnClickListener(myClick);
        
        Button btn_LayoutChange = (Button) findViewById(R.id.btnLayoutChange);
        btn_LayoutChange.setOnClickListener(myClick);
        
        Button btn_ListActivityDemo = (Button) findViewById(R.id.btnListActivityDemo);
        btn_ListActivityDemo.setOnClickListener(myClick);
        
        Button btn_DrawView = (Button) findViewById(R.id.btnDrawView);
        btn_DrawView.setOnClickListener(myClick);
        
    }
    
    @Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// TODO Auto-generated method stub
		super.onCreateOptionsMenu(menu);
//		menu.add(R.string.menu_Add);
//		menu.add(R.string.menu_Del);
//		menu.add(R.string.menu_Exit);
		menu.add(0, ADD_ID, 0, R.string.menu_Add);
		menu.add(0, DEL_ID, 1, R.string.menu_Del);
		menu.add(0, EXIT_ID, 2, R.string.menu_Exit);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// TODO Auto-generated method stub
		switch (item.getItemId()) {
		case ADD_ID:
			setTitle("Menu ADD is clicked");
			break;
		case DEL_ID:
			setTitle("Menu DEL is clicked");
			break;
		case EXIT_ID:
			finish();
			break;

		default:
			break;
		}
		return super.onOptionsItemSelected(item);
	}

	@Override
    public void onStart() {
    	super.onStart();
    	Log.v(TAG, "Hello->onStart");
    }
    
    @Override
    public void onPause() {
    	super.onPause();
    	Log.v(TAG, "Hello->onPause");
    }
    
    @Override
    public void onStop() {
    	super.onStop();
    	Log.v(TAG, "Hello->onStop");
    }
    
    @Override
    public void onDestroy() {
    	super.onDestroy();
    	Log.v(TAG, "Hello->onDestroy");
    }
    
    
    
    private OnClickListener myClick = new OnClickListener() {
		
    	@Override
		public void onClick(View arg0) {
			// TODO Auto-generated method stub
    		EditText txtIn = (EditText)findViewById(R.id.EditText01);
    		switch (arg0.getId()) {
			case R.id.btnOK:
				txtIn = (EditText)findViewById(R.id.EditText01);
				TextView tvShow = (TextView)findViewById(R.id.TVShow);				
				tvShow.setText(txtIn.getText().toString() + " Welcome to android! ");
				break;
			case R.id.btnBrowser:
				Uri uriURL = Uri.parse("http://www.qq.com");
				Uri uriCall = Uri.parse("059523467015");
				Intent browserIntent = new Intent(Intent.ACTION_VIEW, uriURL);
				startActivity(browserIntent);
				break;
			case R.id.btnTitle:
				setTitle("Tong's demo");
				break;
			case R.id.btnPlayMusic:
				Intent musicIntent = new Intent();
				musicIntent.setClass(Hello.this, PlayMusic.class);
				startActivity(musicIntent);
				break;
			case R.id.btnShow:
				Intent showIntent = new Intent();
				Bundle myBundle = new Bundle();
				myBundle.putString("STRING_BUNDLE", txtIn.getText().toString());
				showIntent.putExtras(myBundle);
				showIntent.setClass(Hello.this, ShowAll.class);	
				startActivity(showIntent);
				break;
			case R.id.btnLayout:
				Intent layoutIntent = new Intent();
				layoutIntent.setClass(Hello.this, LayOut.class);
				startActivity(layoutIntent);
				break;
			case R.id.btnRLayout:
				Intent rLayoutIntent = new Intent();
				rLayoutIntent.setClass(Hello.this, RelativeLayoutDemo.class);
				startActivity(rLayoutIntent);
				break;
			case R.id.btnTLayout:
				Intent tLayoutIntent = new Intent();
				tLayoutIntent.setClass(Hello.this, TableLayoutDemo.class);
				startActivity(tLayoutIntent);
				break;
			case R.id.btnLayoutChange:
				Intent itLayoutChange = new Intent();
				itLayoutChange.setClass(Hello.this, LayoutChange.class);
				startActivity(itLayoutChange);
				break;
			case R.id.btnListActivityDemo:
				Intent listActivityDemo = new Intent();
				listActivityDemo.setClass(Hello.this, ListActivityDemo.class);
				startActivity(listActivityDemo);
				break;
			case R.id.btnMenuList:
				Intent menulistIntent = new Intent();
				menulistIntent.setClass(Hello.this, MenuList.class);
				startActivity(menulistIntent);
				break;
			case R.id.btnMenuList2:
				Intent menulistIntent2 = new Intent();
				menulistIntent2.setClass(Hello.this, MenuList2.class);
				startActivity(menulistIntent2);
				break;
			case R.id.btnDrawView:
				Intent itDrawView = new Intent();
				itDrawView.setClass(Hello.this, DrawViewDemo.class);
				startActivity(itDrawView);
				break;
			case R.id.btnExit:
				try {
					finish();
				} catch (Throwable e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				break;

			default:
				break;
			}
    		
		}
	};
    
//    private OnClickListener clickListener = new OnClickListener() {
//		
//		@Override
//		public void onClick(DialogInterface arg0, int arg1) {
//			// TODO Auto-generated method stub
//			EditText txtIn = (EditText)findViewById(R.id.EditText01);
//			TextView tvShow = (TextView)findViewById(R.id.TVShow);
//			
//			tvShow.setText(txtIn.getText().toString() + " Welcome to android! ");
//		}
//	};
}